package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {

	r := gin.Default()

	//普通绑定
	//http://localhost:8080/user/gin/post  -  可以匹配
	//http://localhost:8080/user/gin/post/match/all  -  不可以匹配
	r.GET("/user/:name/:action", func(c *gin.Context) {
		name := c.Param("name")
		action := c.Param("action")
		c.JSON(http.StatusOK, gin.H{
			"name":   name,
			"action": action,
		})
	})

	//泛绑定
	//*表示可以匹配 / 后面所有
	//http://localhost:8080/posts/gin/delete  -  可以匹配
	//http://localhost:8080/posts/gin/delete/match/all  -  可以匹配
	r.GET("/posts/:name/*action", func(c *gin.Context) {
		name := c.Param("name")
		action := c.Param("action")
		c.JSON(http.StatusOK, gin.H{
			"name":   name,
			"action": action,
		})
	})

	//静态资源
	//需要先 go build , 然后通过 .exe 文件执行, 否则会找不到对应的文件
	//http://localhost:8080/images/soul_gin.jpg
	r.Static("/images", "./images")
	//http://localhost:8080/static/curl.txt
	r.StaticFS("/static", http.Dir("./static"))
	//http://localhost:8080/index
	r.StaticFile("index", "index.html")

	r.Run()
}
